//
//  WBNavigonViewController.swift
//  weibo
//
//  Created by 林帆 on 2017/3/10.
//  Copyright © 2017年 林帆. All rights reserved.
//

import UIKit

class WBNavigonViewController: UINavigationController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.navigationBar.isHidden = true
    }
    
    // 重写 push 方法
    // viewController 是被push 的控制器, 设置左侧的按钮作为返回按钮
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        print(viewController)
        // 隐藏底部的 TabBar
        if childViewControllers.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
            
            // 判断控制器的类型
            if let vc = viewController as? WBBaseViewController {
                var title = "返回"
                
                if childViewControllers.count == 1 {
                    title = childViewControllers.first?.title ?? "返回"
                }
                
                //取出自定义的navItem
                
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, fontSize: 16, width: 40, target: self, action: #selector(popTpParent))
            }
            
        }
        
        super.pushViewController(viewController, animated: true)
        
    }
    
    @objc fileprivate func popTpParent() {
        popViewController(animated: true)
    }
    

}
